﻿

Public Class PanelSfxOptions

    'Fields :
    Private _LocalSfxOptions As New SfxOptions
    Private _TargetNode As ZipNode
    Public WriteOnly Property TargetNode As ZipNode
        Set(value As ZipNode)
            _TargetNode = value
            _LocalSfxOptions.CopyFrom(_TargetNode.ZipSettings.SfxOptions)
            ShowSfxOptions()
        End Set
    End Property
    'Show Sfx Options:
    Private Sub ShowSfxOptions()
        KTB_Name.Text = _LocalSfxOptions.Name
        KTB_Version.Text = _LocalSfxOptions.Version
        KTB_Copyright.Text = _LocalSfxOptions.Copyright
        KTB_Description.Text = _LocalSfxOptions.Description

        If _LocalSfxOptions.Flavor = Zip.SelfExtractorFlavor.ConsoleApplication Then
            If _LocalSfxOptions.Quiet = False Then
                KRB_ConsoleVisible.Checked = True
            Else
                KRB_ConsoleHidden.Checked = True
            End If
        Else
            KRB_Gui.Checked = True
        End If
        KCB_ExtractExisting.SelectedIndex = _LocalSfxOptions.ExtractExistingAction
        KCB_RemoveUnpacked.Checked = _LocalSfxOptions.RemoveUnpacked
        KTB_Command.Text = _LocalSfxOptions.Command
        KTB_CompilerSwitches.Text = _LocalSfxOptions.CompilerSwitches
    End Sub
    'Pages :
    Private Sub BSHG_Product_Click(sender As System.Object, e As System.EventArgs) Handles BSHG_Product.Click
        BSHG_Product.Checked = ButtonCheckState.Checked
        BSHG_Options.Checked = ButtonCheckState.Unchecked
        BSHG_Advanced.Checked = ButtonCheckState.Unchecked
        TC_SfxOptions.SelectTab("Page_Product")
    End Sub
    Private Sub BSHG_Options_Click(sender As System.Object, e As System.EventArgs) Handles BSHG_Options.Click
        BSHG_Product.Checked = ButtonCheckState.Unchecked
        BSHG_Options.Checked = ButtonCheckState.Checked
        BSHG_Advanced.Checked = ButtonCheckState.Unchecked
        TC_SfxOptions.SelectTab("Page_Options")
    End Sub
    Private Sub BSHG_Advanced_Click(sender As System.Object, e As System.EventArgs) Handles BSHG_Advanced.Click
        BSHG_Options.Checked = ButtonCheckState.Unchecked
        BSHG_Product.Checked = ButtonCheckState.Unchecked
        BSHG_Advanced.Checked = ButtonCheckState.Checked
        TC_SfxOptions.SelectTab("Page_Advanced")
    End Sub
    'flavor :
    Private Sub KRB_ConsoleVisible_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles KRB_ConsoleVisible.CheckedChanged
        If KRB_ConsoleVisible.Checked = True Then
            KGB_Gui.Enabled = False
            KTB_Title.Text = Nothing
            PB_SfxIcon.Image = Nothing
        End If
    End Sub
    Private Sub KRB_ConsoleHidden_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles KRB_ConsoleHidden.CheckedChanged
        If KRB_ConsoleHidden.Checked = True Then
            KGB_Gui.Enabled = False
            KTB_Title.Text = Nothing
            PB_SfxIcon.Image = Nothing
        End If
    End Sub
    Private Sub KRB_Gui_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles KRB_Gui.CheckedChanged
        If KRB_Gui.Checked = True Then
            KGB_Gui.Enabled = True
            KTB_Title.Text = _LocalSfxOptions.Title
            _IconFile = _LocalSfxOptions.IconFile
            PB_SfxIcon.Image = Image.FromFile(_IconFile)
        End If
    End Sub
    Private _IconFile As String = ""
    Private Sub KLL_ChooseSfxIcon_LinkClicked(sender As System.Object, e As System.EventArgs) Handles KLL_ChooseSfxIcon.LinkClicked
        Dim dr As DialogResult = OFD.ShowDialog(Me)
        If dr = Windows.Forms.DialogResult.OK Then
            _IconFile = OFD.FileName
            PB_SfxIcon.Image = Image.FromFile(_IconFile)
        End If
    End Sub
    Private Sub KLL_DefaultSfxIcon_LinkClicked(sender As System.Object, e As System.EventArgs) Handles KLL_DefaultSfxIcon.LinkClicked
        _IconFile = DefaultSfxIcon()
        PB_SfxIcon.Image = Image.FromFile(_IconFile)
    End Sub
    Private Sub BSA_ResetExtractExisting_Click(sender As System.Object, e As System.EventArgs) Handles BSA_ResetExtractExisting.Click
        KCB_ExtractExisting.SelectedIndex = 0
    End Sub
    'Actions :
    Public Sub Reset()
        _LocalSfxOptions.Reset()
        ShowSfxOptions()
    End Sub
    Public Sub Cancel()
        _LocalSfxOptions.CopyFrom(_TargetNode.ZipSettings.SfxOptions)
        ShowSfxOptions()
    End Sub
    Public Sub Apply()
        _TargetNode.ZipSettings.SfxOptions.Name = KTB_Name.Text
        _TargetNode.ZipSettings.SfxOptions.Version = KTB_Version.Text
        _TargetNode.ZipSettings.SfxOptions.Copyright = KTB_Copyright.Text
        _TargetNode.ZipSettings.SfxOptions.Description = KTB_Description.Text
        If KRB_ConsoleHidden.Checked = True Then
            _TargetNode.ZipSettings.SfxOptions.Flavor = Zip.SelfExtractorFlavor.ConsoleApplication
            _TargetNode.ZipSettings.SfxOptions.Quiet = True
        ElseIf KRB_ConsoleVisible.Checked = True Then
            _TargetNode.ZipSettings.SfxOptions.Flavor = Zip.SelfExtractorFlavor.ConsoleApplication
            _TargetNode.ZipSettings.SfxOptions.Quiet = False
        ElseIf KRB_Gui.Checked = True Then
            _TargetNode.ZipSettings.SfxOptions.Flavor = Zip.SelfExtractorFlavor.WinFormsApplication
            _TargetNode.ZipSettings.SfxOptions.Title = KTB_Title.Text
            _TargetNode.ZipSettings.SfxOptions.IconFile = _IconFile
        End If
        _TargetNode.ZipSettings.SfxOptions.ExtractExistingAction = CType(KCB_ExtractExisting.SelectedIndex, Zip.ExtractExistingFileAction)
        _TargetNode.ZipSettings.SfxOptions.RemoveUnpacked = KCB_RemoveUnpacked.Checked
        _TargetNode.ZipSettings.SfxOptions.Command = KTB_Command.Text
        _TargetNode.ZipSettings.SfxOptions.CompilerSwitches = KTB_CompilerSwitches.Text
    End Sub

End Class
